const fs = require('fs')
const path = require('path')

let size = 0

function calFolderSize(dirPath) {
    // 1. 将输入的path转换成绝对路径
    dirPath = path.resolve(__dirname, dirPath)
    // 2. 判断当前路径是文件还是文件夹
    const statObj = fs.statSync(dirPath);
    if (statObj.isFile()) {
        return statObj.size;
    }
    // 3. 如果是文件夹， 则读取当前文件夹
    let files = fs.readdirSync(dirPath)
    files = files.filter(file => !file.startsWith('.'))
    for (let i = 0; i < files.length; i++) {
        filePath = path.join(dirPath, files[i]);
        let res = calFolderSize(filePath);
        if (res !== undefined) {
            size += res;
        }
    }
}

calFolderSize('./01_sort')
console.log(size);